define(backboneCommon.getViewDefine("account.login"), function ($,require,Collection,tpl) {
    var backboneView= Backbone.View.extend({
        el: '#login_container_body',
        events: {
            'focusin  #txt_username': 'inputFocusin',
            'focusin  #txt_password': 'inputFocusin',
            'focusout  #txt_username': 'inputFocusout',
            'focusout  #txt_password': 'inputFocusout',
            'keydown #txt_username': 'enterKeyword',
            'keydown #txt_password': 'enterKeyword',
            'click #btn_login': 'submitLogin'
        },
        initialize: function () {
            this.listenTo(this.model, 'login:Info', this.loginCallback);
            this.render();
        },
        render:function(json){
            var templateHtml=_.template(tpl);
            this.$el.html(templateHtml(json));
        },
        initMain:function(type){
            this.extObject={};
            this.elementModel={};
            this.elementModel.formLogin=$("#form_login");
            this.extObject.formLogin=this.elementModel.formLogin.ExtParsley();
        },
        inputFocusin:function(e){$(e.currentTarget).parent().addClass("login-focus")},
        inputFocusout:function(e){$(e.currentTarget).parent().removeClass("login-focus")},
        enterKeyword:function(e){if(e.keyCode == 13) {this.submitLogin()}},
        _checkLoginFrom:function(){
            return this.extObject.formLogin.validate();
        },
        submitLogin:function(){
            if(this._checkLoginFrom()){
                var ajaxdata =this.elementModel.formLogin.ExtFormValue().getValues();
                console.log(ajaxdata);
                this.collection.submitLogin(ajaxdata);
            }
        },
        loginCallback: function () {
            var res=this.model.get("dataLogin");
            if (res.success) {
                $.ExtCommon.goLocationHref("#report/overview");
            }else{
                //todo 定位提示
                this.extObject.formLogin.setExtSourceErrMsg($("#txt_email"),res.msg);
            }
        }
    });
    var viewModel=function(param,urlParam){
        this.collection= new Collection();
        this.model=this.collection.model;
        this.view=new backboneView({collection:this.collection,model:this.model});
        this.view.initMain(urlParam.view);
    };
    viewModel.prototype={};
    return viewModel;
});